Core Architecture
Duet follows a client-server architecture where:- SSH Server handles incoming connections using Charm’s Wish framework
- Room Manager orchestrates collaborative sessions with isolated workspaces
- Terminal Emulator provides shared PTY access with vt10x emulation
- Bubble Tea UI renders the interactive terminal interface for each client
System Components
Data Flow
Connection Flow
- Client connects via SSH to the server on port 2222
- Wish middleware processes the connection and extracts session info
- Bubble Tea creates a new TUI model with the Room Manager reference
- User selects “Create Room” or “Join Room” from the launch screen
- Room Manager creates/retrieves the room and registers the client
- Terminal starts (or connects to existing shared terminal)
- Client subscribes to terminal updates via broadcast channel
Terminal Input/Output Flow
Room Event Broadcasting
Key Design Patterns
Publisher-Subscriber Pattern
The terminal uses a pub-sub pattern for broadcasting updates to all connected clients:Shared State with Mutex Protection
Both Room and Terminal usesync.RWMutex for thread-safe access:
Isolated Workspaces
Each room gets its own workspace directory:cmd.Dir = workspaceDir, providing file system isolation.
Technology Stack
Core Dependencies
- SSH Server:
github.com/charmbracelet/ssh- SSH protocol implementation - Wish:
github.com/charmbracelet/wish- SSH middleware framework - Bubble Tea:
github.com/charmbracelet/bubbletea- TUI framework - PTY:
github.com/creack/pty- Pseudo-terminal interface - vt10x:
github.com/hinshun/vt10x- Terminal emulator - Lipgloss:
github.com/charmbracelet/lipgloss- Style definitions
Optional Integrations
- AI Client: Cloudflare Workers AI integration for chat assistance
- Sandbox: Remote command execution via worker
- SSH Server - Wish middleware and connection handling
- Room Management - Room lifecycle and client coordination
- Terminal Sharing - PTY and vt10x emulation details